/**********************************************************

     文件名称: mv_com.c

     项目功能: 修改商品信息 

     作者: 佳奇

     邮箱: 1374804492@qq.com 

     创建时间: Fri 26 Aug 2022 10:46:53 PM CST

**********************************************************/


#include <stdio.h>
#include <stdlib.h>
#include "sup_mgr.h"

//	修改商品信息
void mv_com(com_list* demo)
{
	int com_id;
	com_list* s1 = NULL;

	printf("\n********修改商品信息模式********\n");

	while(1)
	{
		system("clear");
		printf("\n请输入您要修改商品的条码(编号):");
		while(!geshipanduan(scanf("%d", &com_id)));
		c_buffer();

		s1 = q_com(demo, com_id);

		if(s1 == NULL)
		{
			fprintf(stderr, "\n未找到商品！");
			printf("\n是否继续执行修改操作(y/n):");

			if(getchar() == 'y')
				continue;
			else return;
		}

		printf("\n商品原信息如下:");

		printf("商品条码:%d", s1->data->barcode);
		printf("\n商品名称:%s", s1->data->com_name);
		printf("\n商品单价:%d", s1->data->unit);
		printf("\n商品厂家:%s", s1->data->manu);
		printf("\n商品数量:%d", s1->data->num);
		printf("\n商品余量:%d", s1->data->allow);

		printf("\n即将更改为\n");
		printf("**************\n");
		printf("商品条码(编号):");

		int id;
		while(1)
		{
			//	判断格式是否输入正确
			while(!geshipanduan(scanf("%d", &id)));
			c_buffer();
			
			//	判断商品条码是否已经存在 要确保商品条码的唯一性
			if(q_com(demo, id))
			{
				printf("\n商品条码(编号)已存在！\n");
				printf("请重新输入:");
			}
			else break;
		}

		s1->data->barcode = id;

		printf("\n商品名称：");
		scanf("%30s", s1->data->com_name);
		c_buffer();
		printf("\n商品单价：");
		while(!geshipanduan(scanf("%d", &s1->data->unit)));
		c_buffer();
		printf("\n商品厂家：");
		scanf("%60s", s1->data->manu);
		c_buffer();
		printf("\n商品数量：");
		while(!geshipanduan(scanf("%d", &s1->data->num)));
		c_buffer();
		printf("\n商品余量：");
		while(!geshipanduan(scanf("%d", &s1->data->allow)));
		c_buffer();
	
		printf("\n商品信息修改成功!\n");
		printf("是否继续执行修改操作(y/n):");
		if(getchar() == 'y')
			continue;
		else break;
	}
		c_buffer();
}

















